<script type="text/javascript">
   
    function delCopyrighter(btn){
		$(btn).closest("ul").remove();
	}
    
	function initFields(){
		$( "#copyrightApplicationForm .datepicker" ).datepicker({ 
			dateFormat: "yy-mm-dd",
			changeMonth: true,
			changeYear: true
		});
				
		$("#copyrightApplicationForm span.ui-datepicker-trigger").bind("click",function(){
			$(this).parent().find(".datepicker").datepicker("show");
		});
		
		//should init at top privilege
		initRadioOrCheckBoxValues();
		
		initPublishStatus();
		initSoftIntroduction();
		initCopyrighter();
		initRightObtainMode();
		initRightScope();
		initSoftwareIdentifyMaterial();
		bindEvents();
		init_toolTips();
	}
	
	function initRadioOrCheckBoxValues(){
		var value = '<s:property value="copyrightApplication.rightObtainMode"/>';
		
		$("#copyrightApplicationForm input:radio[name='copyrightApplication.rightObtainMode']").each(function(){
			if($(this).val() == value){
				$(this).attr('checked',true);
				return;
			}
		});
		
		value = '<s:property value="copyrightApplication.inheritanceMode"/>';
		$("#copyrightApplicationForm input:radio[name='copyrightApplication.inheritanceMode']").each(function(){
			if($(this).val() == value){
				$(this).attr('checked',true);
				return;
			}
		});
		
		
		value = '<s:property value="copyrightApplication.rightScope"/>';
		$("#copyrightApplicationForm input:radio[name='copyrightApplication.rightScope']").each(function(){
			if($(this).val() == value){
				$(this).attr('checked',true);
				return;
			}
		});
		
		value = '<s:property value="copyrightApplication.developMode"/>';
		$("#copyrightApplicationForm input:radio[name='copyrightApplication.developMode']").each(function(){
			
			if($(this).val() == value){
				$(this).attr('checked',true);
				return;
			}
		});
		
		value = '<s:property value="copyrightApplication.publishStatus"/>';
		$("#copyrightApplicationForm input:radio[name='copyrightApplication.publishStatus']").each(function(){
			if($(this).val() == value){
				$(this).attr('checked',true);
				return;
			}
		});
		
		value = '<s:property value="copyrightApplication.developCircs"/>';
		$("#copyrightApplicationForm input:radio[name='copyrightApplication.developCircs']").each(function(){
			if($(this).val() == value){
				$(this).attr('checked',true);
				return;
			}
		});
		
		/*value = '<s:property value="copyrightApplication.developCircsExplain"/>';
		if(value == '0'){
			$("#copyrightApplicationForm input:checkbox[name='copyrightApplication.developCircsExplain']").attr('checked',true);
		}
		
		value = '<s:property value="copyrightApplication.origSoftRegCircs"/>';
		if(value == '0'){
			$("#copyrightApplicationForm input:checkbox[name='copyrightApplication.origSoftRegCircs']").attr('checked',true);
		}*/
		
		var partValues = '<s:property value="copyrightApplication.rightScopePart"/>';
		if(partValues != ''){
			var splitedPartValues = partValues.split(",");
			for(var i = 0 ; i < splitedPartValues.length ; i ++){
				$(":checkbox[name='copyrightApplication.rightScopePart'][value="+splitedPartValues[i]+"]").attr("checked","true");
			}
		}
		
	}
	
	
	function initSoftIntroduction(){
		var checked = $("#copyrightApplicationForm input:radio[name='copyrightApplication.developCircs']:checked").val();
		if(checked == "1"){
			_hideModifyPanel();
		}else if(checked == "2"){
			_showModifyPanel();
		}
		
		$("#copyrightApplicationForm input:radio[name='copyrightApplication.developCircs']").bind("click",function(){
			if($(this).val() == "1"){
			 	_hideModifyPanel();
			 }else if($(this).val() == "2"){
			 	_showModifyPanel();
			 }
		});
	}
	
	function _showModifyPanel(){
		$("#softIntroModifyContainer").show();
	}
	
	function _hideModifyPanel(){
		$("#softIntroModifyContainer").hide();
	}
	
	function initCopyrighter(){
		$("#copyrighterItem ul:first button.btn-danger").hide();
		$("#copyrighterItem ul:not(:first) button.btn-danger").show();
		$("#copyrighterItem ul:not(:first) button.btn-info").hide();
		
		$("#copyrighterItem ul:first :input[name='copyrightApplication.hasLetter1']").parent().parent().hide();
		$("#copyrighterItem ul:first :input[name='copyrightApplication.hasLetter1']").attr('disabled',true);
		
		$("#copyrighterItem ul:not(:first) button.btn-info").hide();
				
		$("#copyrightApplicationForm :input").bind('click focus',function(){
			$("#copyrightApplicationForm ul.highlighted").removeClass("highlighted");
			var current_li = $(this).closest("ul").not('.matrix').not('.buttons');
			current_li.addClass("highlighted");
		});
				
				
		$("#copyrighterItem ul:first button.btn-info").bind('click',function(){
			$("#copyrighterItem").append( '<ul class="item">' + $("#copyrighterItem ul:first").html()  + '</ul>');
			
			$("#copyrighterItem ul:last :input[name='copyrightApplication.hasLetter1']").parent().parent().show();
			$("#copyrighterItem ul:last :input[name='copyrightApplication.hasLetter1']").removeAttr('disabled');
			
			/*
			 * var index = $("#copyrighterItem ul").index($("#copyrighterItem
			 * ul:last"));
			 * 
			 * $("#copyrighterItem ul:last :input").each(function(){
			 * $(this).attr("name",$(this).prop("name").replace("copyrightApplication.copyrighters[0]","copyrightApplication.copyrighters[" +
			 * index + "]")); });
			 */
			$("#copyrighterItem ul:not(:first) button.btn-info").hide();
			$("#copyrighterItem ul:not(:first) button.btn-danger").show();
			$("#copyrighterItem ul:not(:first).highlighted").removeClass("highlighted");
				
		});
	}
	
	/* Right Obtain Mode --BEGIN */
	function initRightObtainMode(){
		
		var checkedRightObtainMode = $("#copyrightApplicationForm input:radio[name='copyrightApplication.rightObtainMode']:checked").val();
		if(checkedRightObtainMode == "1"){
			_disableInheritanceMode();
		}else if(checkedRightObtainMode == "2"){
			_enableInheritanceMode();
		}
		
		$("#copyrightApplicationForm input:radio[name='copyrightApplication.rightObtainMode']").bind("click",function(){
			if($(this).val() == "1"){
			 	_disableInheritanceMode();
			 }else if($(this).val() == "2"){
			 	_enableInheritanceMode();
			 }
		});
		
	}
	
	function _disableInheritanceMode(){
		$("#copyrightApplicationForm input[name='copyrightApplication.inheritanceMode']:first").attr("checked",true);
		$("#copyrightApplicationForm input[name='copyrightApplication.inheritanceMode']").attr("disabled",true);
		
		$("#copyrightApplicationForm input[name='copyrightApplication.softRegChecked']").attr("disabled",true);
		$("#copyrightApplicationForm input[name='copyrightApplication.softRegChecked']").removeAttr('checked');
		
		$("#copyrightApplicationForm input[name='copyrightApplication.regNumber']").val('');
		$("#copyrightApplicationForm input[name='copyrightApplication.regNumber']").attr("disabled",true);
		
		$("#copyrightApplicationForm input[name='copyrightApplication.changeNumber']").attr("disabled",true);
		$("#copyrightApplicationForm input[name='copyrightApplication.changeNumber']").val('');
		
		$("#copyrightApplicationForm input[name='copyrightApplication.softChangedChecked']").attr("disabled",true);
		$("#copyrightApplicationForm input[name='copyrightApplication.softChangedChecked']").removeAttr('checked');
	}
	
	function _enableInheritanceMode(){
		$("#copyrightApplicationForm input[name='copyrightApplication.inheritanceMode']").removeAttr("disabled");
		$("#copyrightApplicationForm input[name='copyrightApplication.softRegChecked']").removeAttr("disabled");	
		$("#copyrightApplicationForm input[name='copyrightApplication.regNumber']").removeAttr("disabled");	
		$("#copyrightApplicationForm input[name='copyrightApplication.changeNumber']").removeAttr("disabled");	
		$("#copyrightApplicationForm input[name='copyrightApplication.softChangedChecked']").removeAttr("disabled");	
	}
	/* Right Obtain Mode --END */
	
	
	/* Right Scope --BEGIN */
	function initRightScope(){
		var checkedRightScope = $("#copyrightApplicationForm input:radio[name='copyrightApplication.rightScope']:checked").val();
		var rightScopePart = $("#copyrightApplicationForm input[name='copyrightApplication.rightScopePart']");
		// All
		if(checkedRightScope == "1"){
			rightScopePart.attr("disabled",true);	
		}else if(checkedRightScope == "2"){
		// part
			rightScopePart.removeAttr("disabled");	
		}
		
		$("#copyrightApplicationForm input:radio[name='copyrightApplication.rightScope']").bind("click",function(){
			 if($(this).val() == "1"){
			 	rightScopePart.attr("disabled",true);
			 	rightScopePart.removeAttr("checked");
			 }else if($(this).val() == "2"){
			 	rightScopePart.removeAttr("disabled");	
			 }
		});
	}
	/* Right Scope --END */
	
	
	/* Software Identify Material --BEGIN */
	function initSoftwareIdentifyMaterial(){
		var checkedDifmatReferMode = $("#copyrightApplicationForm input:radio[name='copyrightApplication.difmatReferMode']:checked").val();
		if(checkedDifmatReferMode == "1"){
			_disableExceptionMode();
		}else if(checkedDifmatReferMode == "2"){
			_enableExceptionMode();
		}
		
		$("#copyrightApplicationForm input:radio[name='copyrightApplication.difmatReferMode']").bind("click",function(){
			 if($(this).val() == "1"){
			 	_disableExceptionMode();
			 }else if($(this).val() == "2"){
			 	_enableExceptionMode();
			 }
		});
		
	}
	
	function _disableExceptionMode(){
		$("#copyrightApplicationForm input[name='copyrightApplication.isMutilDoc']").removeAttr("disabled");
		$("#copyrightApplicationForm input[name='copyrightApplication.difmatReferModeExcep']").attr("disabled",true);
		
		$("#copyrightApplicationForm input[name='copyrightApplication.mutilDocType']").removeAttr("disabled");
		$("#copyrightApplicationForm input[name='copyrightApplication.difmatReferPages']").attr("disabled",true);
		
		var isMutilDoc = '<s:property value="copyrightApplication.isMutilDoc"/>';
		
		$("#copyrightApplicationForm input[name='copyrightApplication.isMutilDoc']").each(function(){
			if($(this).val() == isMutilDoc){
				$(this).attr('checked',true);
			}
		});
	}
	
	function _enableExceptionMode(){
		$("#copyrightApplicationForm input[name='copyrightApplication.difmatReferModeExcep']").removeAttr("disabled");
		$("#copyrightApplicationForm input[name='copyrightApplication.isMutilDoc']").attr("disabled",true);
		
		$("#copyrightApplicationForm input[name='copyrightApplication.mutilDocType']").attr("disabled",true);
		$("#copyrightApplicationForm input[name='copyrightApplication.difmatReferPages']").removeAttr("disabled");
		
		var difmatReferModeExcep = '<s:property value="copyrightApplication.difmatReferModeExcep"/>';
		
		$("#copyrightApplicationForm input[name='copyrightApplication.difmatReferModeExcep']").each(function(){
			if($(this).val() == difmatReferModeExcep){
				$(this).attr('checked',true);
			}
		});
	}
	/* Software Identify Material --END */
	
	
	
	function initPublishStatus(){
		var publishStatus = $("#copyrightApplicationForm input:radio[name='copyrightApplication.publishStatus']:checked").val();
		if(publishStatus == "0"){
			_hidePublishInfo();
		}else if(publishStatus == "1"){
			_showPublishInfo();
		}
		
        $("#copyrightApplicationForm input:radio[name='copyrightApplication.publishStatus']").click(function (e) { 
         	if($(this).val() == '0'){
          		_hidePublishInfo();
          	}else if($(this).val() == '1'){
          		_showPublishInfo();
          	}
        });
	}
	
	
	function _hidePublishInfo(){
		$("#publishedInfoContainer").hide();
		$("#publishedInfoContainer :input").each(function(){
			if($(this).attr('name') != 'copyrightApplication.appearAreaCountry')
				$(this).val('');
		});
	}
	
	function _showPublishInfo(){
		$("#publishedInfoContainer").show();
	}
	
	function preSubmit(){
		 
		var _names = "";
		var _peopleTypes = "";
		var _countries = "";
		var _provinces = "";
		var _citys = "";
		var _idTypes = "";
		var _idNumbers = "";
		/*var _gardens = "";*/
		var _busTypes = "";
		$("#copyrighterItem :input[name='_names']").each(function(){
			_names += (_names == "" ? "" : "&") + $(this).val();
		});
		
		$("#copyrighterItem :input[name='_peopleTypes']").each(function(){
			_peopleTypes += (_peopleTypes == "" ? "" : "&") + $(this).val();
		});
		$("#copyrighterItem :input[name='_countries']").each(function(){
			_countries += (_countries == "" ? "" : "&") + $(this).val();
		});
		$("#copyrighterItem :input[name='_provinces']").each(function(){
			_provinces += (_provinces == "" ? "" : "&") + $(this).val();
		});
		$("#copyrighterItem :input[name='_citys']").each(function(){
			_citys += (_citys == "" ? "" : "&") + $(this).val();
		});
		$("#copyrighterItem :input[name='_idTypes']").each(function(){
			_idTypes += (_idTypes == "" ? "" : "&") + $(this).val();
		});
		$("#copyrighterItem :input[name='_idNumbers']").each(function(){
			_idNumbers += (_idNumbers == "" ? "" : "&") + $(this).val();
		});
		/*$("#copyrighterItem :input[name='_gardens']").each(function(){
			_gardens += (_gardens == "" ? "" : "&") + $(this).val();
		});*/
		$("#copyrighterItem :input[name='_busTypes']").each(function(){
			_busTypes += (_busTypes == "" ? "" : "&") + $(this).val();
		});
		
		$("#copyrightApplicationForm input:hidden[name='copyrightApplication.names']").val(_names);
		$("#copyrightApplicationForm input:hidden[name='copyrightApplication.peopleTypes']").val(_peopleTypes);
		$("#copyrightApplicationForm input:hidden[name='copyrightApplication.countries']").val(_countries);
		
		$("#copyrightApplicationForm input:hidden[name='copyrightApplication.provinces']").val(_provinces);
		$("#copyrightApplicationForm input:hidden[name='copyrightApplication.citys']").val(_citys);
		$("#copyrightApplicationForm input:hidden[name='copyrightApplication.idTypes']").val(_idTypes);
		
		$("#copyrightApplicationForm input:hidden[name='copyrightApplication.idNumbers']").val(_idNumbers);
		/*$("#copyrightApplicationForm input:hidden[name='copyrightApplication.gardens']").val(_gardens);*/
		$("#copyrightApplicationForm input:hidden[name='copyrightApplication.busTypes']").val(_busTypes);
		
		
		/*if($("#copyrightApplicationForm input:checkbox[name='copyrightApplication.developCircsExplain']:not(:checked)").length > 0){
			$("#copyrightApplicationForm input:checkbox[name='copyrightApplication.developCircsExplain']").val("");
		}
		
		if($("#copyrightApplicationForm input:checkbox[name='copyrightApplication.origSoftRegCircs']:not(:checked)").length > 0){
			$("#copyrightApplicationForm input:checkbox[name='copyrightApplication.origSoftRegCircs']").val("");
		}
		
		if($("#copyrightApplicationForm input:checkbox[name='copyrightApplication.isSoftReg']:not(:checked)").length > 0){
			$("#copyrightApplicationForm input:checkbox[name='copyrightApplication.isSoftReg']").val("");
		}
		
		if($("#copyrightApplicationForm input:checkbox[name='copyrightApplication.isSoftChanged']:not(:checked)").length > 0){
			$("#copyrightApplicationForm input:checkbox[name='copyrightApplication.isSoftChanged']").val("");
		}
		
		
		alert("test" + $("#copyrightApplicationForm input:checkbox[name='copyrightApplication.developCircsExplain']").val());
		*/
		return true;	
		
	}
	
	function bindEvents(){
		 $("#copyrightApplication_button_softNumber").click(function (e) {  
             var stuObj = { name: "xy", age: 22 };  
             var whObj = { width: 760, height: 1150 };  
             var returnValue = openShowModalDialog('softClassNumber.html', stuObj, whObj, e);
             if (returnValue) {  
            	 $("#copyrightApplicationForm :input[name='copyrightApplication.softNumber']").val(returnValue);
             }  
         }); 
		
	}
	
	function openShowModalDialog(url,param,whparam,e){   
        
		 // 传递至子窗口的参数
		 var paramObj = param || { };   
		         
		 // 模态窗口高度和宽度
		 var whparamObj = whparam || { width: 760, height: 1150 };   
		         
		 // 相对于浏览器的居中位置
		 var bleft = ($(window).width() - whparamObj.width) / 2;   
		 var btop = ($(window).height() - whparamObj.height) / 2;   
		         
		 // 根据鼠标点击位置算出绝对位置
		 var tleft = e.screenX - e.clientX;   
		 var ttop = e.screenY - e.clientY;   
		         
		 // 最终模态窗口的位置
		 var left = bleft + tleft;   
		 var top = btop + ttop;   
		         
		 // 参数
		 var p = "help:no;status:yes;center:yes;resizable:no;scroll:auto;";   
		     p += 'dialogWidth:'+(whparamObj.width)+'px;';   
		     p += 'dialogHeight:'+(whparamObj.height)+'px;';   
		     p += 'dialogLeft:' + left + 'px;';   
		     p += 'dialogTop:' + top + 'px;';   
		         
		        
		  return showModalDialog(url,paramObj,p);   
		}
		
		
		
		function init_toolTips(){
			var tips = [{
				name:'copyrightApplication.softFullName',msg:'<fmt:message key="tip.copyrightApplication.softFullName" />'
			},{
				name:'copyrightApplication.softForShort',msg:'<fmt:message key="tip.copyrightApplication.softForShort" />'
			},{
				name:'copyrightApplication.editionNumber',msg:'<fmt:message key="tip.copyrightApplication.editionNumber" />'
			},{
				name:'copyrightApplication.softNumber',msg:'<fmt:message key="tip.copyrightApplication.softNumber" />'
			},{
				id:'copyrightApplication-developCircs-1',msg:'<fmt:message key="tip.copyrightApplication.developCircs.1" />' 
			},{
				id:'copyrightApplication-publishStatus-0',msg:'<fmt:message key="tip.copyrightApplication.publishStatus.0" />'
			},{
				id:'copyrightApplication-publishStatus-1',msg:'<fmt:message key="tip.copyrightApplication.publishStatus.1" />'
			},{
				name:'copyrightApplication.appearAreaCity',msg:'<fmt:message key="tip.copyrightApplication.appearAreaCity" />'
			},{
				id:'copyrightApplication-developMode-0',msg:'<fmt:message key="tip.copyrightApplication.developMode.0" />'
			},{
				id:'copyrightApplication-developMode-1',msg:'<fmt:message key="tip.copyrightApplication.developMode.1" />'
			},{
				id:'copyrightApplication-developMode-2',msg:'<fmt:message key="tip.copyrightApplication.developMode.2" />'
			},{
				id:'copyrightApplication-developMode-3',msg:'<fmt:message key="tip.copyrightApplication.developMode.3" />'
			},{
				id:'copyrightApplication-rightObtainMode-0',msg:'<fmt:message key="tip.copyrightApplication.rightObtainMode.0" />'
			},{
				id:'copyrightApplication-rightObtainMode-1',msg:'<fmt:message key="tip.copyrightApplication.rightObtainMode.1" />'
			},{
				id:'copyrightApplication-inheritanceMode-0',msg:'<fmt:message key="tip.copyrightApplication.inheritanceMode.0" />'
			},{
				id:'copyrightApplication-inheritanceMode-1',msg:'<fmt:message key="tip.copyrightApplication.inheritanceMode.1" />'
			},{
				id:'copyrightApplication-inheritanceMode-2',msg:'<fmt:message key="tip.copyrightApplication.inheritanceMode.2" />'
			},{
				name:'copyrightApplication.softRegChecked',msg:'<fmt:message key="tip.copyrightApplication.isSoftReg" />'
			},{
				name:'copyrightApplication.regNumber',msg:'<fmt:message key="tip.copyrightApplication.regNumber" />'
			},{
				name:'copyrightApplication.changeNumber',msg:'<fmt:message key="tip.copyrightApplication.changeNumber" />'
			},{
				name:'copyrightApplication.hardwareEnv',msg:'<fmt:message key="tip.copyrightApplication.hardwareEnv" />'
			},{
				name:'copyrightApplication.softwareEnv',msg:'<fmt:message key="tip.copyrightApplication.softwareEnv" />'
			},{
				name:'copyrightApplication.programLanguage',msg:'<fmt:message key="tip.copyrightApplication.programLanguage" />'
			},{
				name:'copyrightApplication.sourceCodeCapacity',msg:'<fmt:message key="tip.copyrightApplication.sourceCodeCapacity" />'
			},{
				name:'copyrightApplication.softFunctionAndSpecialty',msg:'<fmt:message key="tip.copyrightApplication.softFunctionAndSpecialty" />'
			},{
				name:'_names',msg:'<fmt:message key="tip.copyrightApplication.name" />'
			},{
				name:'_peopleTypes',msg:'<fmt:message key="tip.copyrightApplication.peopleType" />'
			},{
				name:'_citys',msg:'<fmt:message key="tip.copyrightApplication.city" />'
			},{
				name:'_idNumbers',msg:'<fmt:message key="tip.copyrightApplication.idNumber" />'
			},{
				name:'_busTypes',msg:'<fmt:message key="tip.copyrightApplication.busType" />'
			},{
				name:'copyrightApplication.hasLetter1',msg:'<fmt:message key="tip.copyrightApplication.hasLetter1" />'
			},{
				name:'copyrightApplication.sqrname',msg:'<fmt:message key="tip.copyrightApplication.sqrname" />'
			},{
				name:'copyrightApplication.sqraddress',msg:'<fmt:message key="tip.copyrightApplication.sqraddress" />'
			},{
				name:'copyrightApplication.sqrpostCode',msg:'<fmt:message key="tip.copyrightApplication.sqrpostCode" />'
			},{
				name:'copyrightApplication.sqrcontactPerson',msg:'<fmt:message key="tip.copyrightApplication.sqrcontactPerson" />'
			},{
				name:'copyrightApplication.sqrphone',msg:'<fmt:message key="tip.copyrightApplication.sqrphone" />'
			},{
				name:'copyrightApplication.sqremail',msg:'<fmt:message key="tip.copyrightApplication.sqremail" />'
			},{
				name:'copyrightApplication.sqrmobile',msg:'<fmt:message key="tip.copyrightApplication.sqrmobile" />'
			},{
				name:'copyrightApplication.sqrfax',msg:'<fmt:message key="tip.copyrightApplication.sqrfax" />'
			},{
				id:'copyrightApplication-difmatReferMode-0',msg:'<fmt:message key="tip.copyrightApplication.difmatReferMode.0" />'
			},{
				id:'copyrightApplication-difmatReferMode-1',msg:'<fmt:message key="tip.copyrightApplication.difmatReferMode.1" />'
			},{
				id:'copyrightApplication-isMutilDoc-1',msg:'<fmt:message key="tip.copyrightApplication.isMutilDoc.1" />'
			},{
				name:'copyrightApplication.mutilDocType',msg:'<fmt:message key="tip.copyrightApplication.mutilDocType" />'
			},{
				name:'copyrightApplication.difmatReferPages',msg:'<fmt:message key="tip.copyrightApplication.difmatReferPages" />'
			},{
				name:'copyrightApplication.origSoftModifyDescription',msg:'<fmt:message key="tip.copyrightApplication.origSoftModifyDescription" />'
			}];
			
			/*$("input[name='user.email']").popover({
					title : '<fmt:message key="tip.title" />',
					trigger : 'focus',
					content : '<fmt:message key="signup.tip.email" />'
				});*/
			
			var title = '<fmt:message key="tip.title" />';
			
			for(var i=0; i < tips.length;i++){
				_bindPopover(tips[i].id,tips[i].name,tips[i].msg,title);
			}
			
		}
		
</script>
